<template>
  <ul class='left-menu'>
    <li v-for="(item, index) in menuData" :key="index">
      <p v-if="item.islabel" class="left-menu-title">{{item.label}}</p>
      <span v-else :class="{'hover':true,'color-blue':item.isActive}" @click="changeMenu(item)">{{item.label}}</span>
    </li>
  </ul>
</template>
<script>
import MixIns from '@/mix/mix.js'
export default {
  components: {},
  name: "",
  data() {
    return {
      menuData:[],
      allData:[
        {key:"/center/buyer",children:[
          {label:"求购管理",islabel:true},
          {label:"指定商品求购",router:"/center/buyer/purchase/specify",isActive:true},
          {label:"实单求购",router:"/center/buyer/purchase/realbills",isActive:false},
          {label:"我的订单",islabel:true},
          {label:"第三方订单",router:"/center/buyer/orders/others",isActive:false},
          {label:"风水网自营订单",router:"/center/buyer/orders/selfSupport",isActive:false},
          {label:"采购概况",islabel:true},
          {label:"采购总览",router:"/center/buyer/survey/overview",isActive:false},
        ]},{key:"/center/seller",children:[
            {label:"店铺管理",islabel:true},
            {label:"我的店铺",router:"/center/seller/shopManage/myshop",isActive:true},
            {label:"店铺总览",router:"/center/seller/shopManage/shopview",isActive:false},
            {label:"报价管理",islabel:true},
            {label:"我的报价",router:"/center/seller/offerManage/myoffer",isActive:true},
            {label:"我的订单",islabel:true},
            {label:"订单管理",router:"/center/seller/myorder/orderManage",isActive:false},
            {label:"商品管理",islabel:true},
            {label:"商品列表",router:"/center/seller/product/productList",isActive:false},
            {label:"新增商品",router:"/center/seller/product/newproduct",isActive:false},
        ]},{key:"/center/mycenter",children:[
            {label:"个人资料",islabel:true},
            {label:"基础资料",router:"/center/mycenter/baseinfo",isActive:true},
            {label:"修改密码",router:"/center/mycenter/password",isActive:false},
            {label:"我的消息",islabel:true},
            {label:"消息中心",router:"/center/mycenter/news/newscenter",isActive:false},
            {label:"我的地址",islabel:true},
            {label:"地址管理",router:"/center/mycenter/address/manage",isActive:false},
            {label:"公司管理",islabel:true},
            {label:"公司认证",router:"/center/mycenter/companyManage/identify",isActive:false},
            {label:"积分管理",islabel:true},
            {label:"我的积分",router:"/center/mycenter/integral/myintegral",isActive:false},
        ]}
      ]
    };
  },
  methods: {
    /**
     * @name 初始化
     */
    init(){
      this.menuData=this.allData.find(val=>this.path.includes(val.key)).children
      this.menuData.forEach(ele=>{ele.isActive=this.path.includes(ele.router)&&ele.router!=""})

    },

    /**
     * @name 切换
     */
    changeMenu(item){
      this.menuData.forEach(ele=>{ele.isActive=false})
      this.$set(item,'isActive',true)
      if(item.router)this.$router.replace(item.router)
    }
  },
  created() {
    this.init()
  },
  mixins:[MixIns]
};
</script>
<style lang="scss" scoped>
.left-menu {
  width: 140px;
  box-sizing: border-box;

  li{
    line-height: 30px;
    font-size: 14px;
    color: #999;

    .left-menu-title{
      font-size: 16px;
      color: #333;
      font-weight: 600;
      line-height: 30px;
      margin: 10px 0;
    }
  }
}
</style>